<?php
require_once '../include/common.inc.php';
switch($act){
	case "edit":
		$uid=$_SESSION['login_uid'];
		$guestexp = '^Guest|'.$cfg['config']['regban']."Guest";
		if(preg_match("/\s+|{$guestexp}/is", $nickname)&&!check_auth('room_admin')){
			$msg="<script>$('.tab').hide();$('#tab_2').show();alert('昵称禁用！');</script>";
			$db->query("update {$tablepre}memberfields set mood='$mood' where uid='$uid'");
			$db->query("update {$tablepre}members set  email='$email',realname='$realname',phone='$phone',sex='$sex' where uid='$uid'");
		}
		else{
			$db->query("update {$tablepre}memberfields set nickname='$nickname',mood='$mood' where uid='$uid'");
			$db->query("update {$tablepre}members set  email='$email',realname='$realname',phone='$phone',sex='$sex' where uid='$uid'");
			header("location:?uid={$uid}");
		}
	break;
	case "editpwd":
		$uid=$_SESSION['login_uid'];
		if($pwd1!=$pwd2){
			$msg="<script>$('.tab').hide();$('#tab_3').show();alert('新密码不一致！');</script>";
		}else{
			$query=$db->query("select * from {$tablepre}members where uid='$uid' and password='".md5($oldpwd)."'");
			if($db->num_rows($query)>0){
				$db->query("update {$tablepre}members set  password='".md5($pwd1)."' where uid='$uid'");
				$msg="<script>$('.tab').hide();$('#tab_3').show();alert('密码已修改！');</script>";
			}
			else
			$msg="<script>$('.tab').hide();$('#tab_3').show();alert('旧密码错误！');</script>";
		}
	break;
}
if(isset($editface) and isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
	$filename='../face/'.$editface.'/'.$_SESSION['login_uid'].'.gif';
	$somecontent = $GLOBALS["HTTP_RAW_POST_DATA"];
    if (!$handle = fopen($filename, 'w+')) {
         print '{code:"#1057", msg:"不能打开文"}';
         exit;
    }
    if (!fwrite($handle, $somecontent)) {
        print '{code:"#1058", msg:"不能打开文"}';
        exit;
    }
    print '{code:"#1057", msg:"成功"}';
    fclose($handle);
	exit();
}
$userinfo=$db->fetch_row($db->query("select m.*,ms.* from {$tablepre}members m,{$tablepre}memberfields ms  where m.uid=ms.uid and m.uid='{$uid}'"));

?>
<!doctype html>
<html>
<head>
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />
<link href="../images/base.css" rel="stylesheet" type="text/css"  />
<link href="../room/images/page.css" rel="stylesheet" type="text/css"  />
<script src="script/jquery.min.js"></script>
<script src="script/JunPage-1.0.1.js?t="<?=time()?>></script>
<script src="script/swfobject.js" ></script>
<title>用户资料</title>
<style>
.main { width: 460px; background: #FDFDFD }
.head { height: 119px; padding-top: 80px; background: url(images/b1.jpg) no-repeat }
#nav { border-top: 1px dotted #FFFFFF; width: 460px; }
#nav a { float: left; display: block; padding: 5px; width: 60px; color: #FFF; background: #09F; font-size: 12px; text-align: center; text-decoration: none; }
#tab { width: 460px; height: 400px; overflow: hidden; font-size: 12px; color: #666 }
#tab td { height: 30px; line-height: 30px; }
#tab tr { border-bottom: 1px dotted #EEEEEE }
#tab input {  border:0px; border-bottom:1px solid #333; width:240px;}
.th { text-align: justify; text-justify: distribute-all-lines; text-align-last: justify; width: 60px; padding-right: 10px; color: #333 }
.user_pic{ width:120px; height:150px; position:absolute; top:203px; right:0px; border:5px solid #FFF}
.user_pic img{width:110px; height:150px; border:1px #CCCCCC solid; padding:1px; }
.bc { border:0px; padding:2px;width:40px; height:20px; color:#FFF; background: #0C0}
.user_edit_pic{ width:460px; height:350px; position:absolute;top:203px; right:0px; background:#FDFDFD; text-align:center; padding-top:30px; display:none;}
</style>
</head>

<body>
<div class="main">
  <div class="head">
    <div class="m10 fl" style="text-shadow:2px 2px 2px #000;">
      <div class="fl mr10" style="width:74px; height:74px;"><img src='../face/img.php?t=p1&u=<?=$userinfo['uid']?>' style="width:74px; height:74px; border:0px"/></div>
      <div class="fl" style="width:350px; height:74px;">
        <div style="height:34px; overflow:hidden">
            <span class="ttff f24 cfff">
          <?=$userinfo['nickname']?>
          </span> &nbsp;<span class="ttff  f14 cfff">
          <?=$userinfo['username']?>
          </span>

            <span class="ttff  f17 cfff" style="    position: absolute;
    padding-left: 22px;
    left: 71px;
    top: 135px;">

                <?php if($rtypeid == 2) { ?>
                    <img src="./images/diamond.png" style="    position: absolute;
    left: 93px;
    top: -6px;
    height: 30px;" alt="">
                    钻石余额: <span style="    padding-left: 35px;"><?=$userinfo['diamond']?></span>
                <?php } ?>
          </span>

        </div>
<!--        <div>-->
<!--          --><?//=showstars($userinfo['onlinetime'])?>
<!--        </div>-->
<!--        <div class="ttff f14 cfff" style="height:20px; overflow:hidden">-->
<!--          --><?//=$userinfo['mood']?>
<!--        </div>-->
      </div>
    </div>
    <div class="cl"></div>
    <div class="fl" id="nav"> 
    <a href="javascript://" onClick="$('.tab').hide();$('#tab_1').show()">用户资料</a>
        <?php
        if($uid==$_SESSION['login_uid']){
            ?>
            <a href="javascript://" style="background:#F63" onClick="$('.tab').hide();$('#tab_2').show()">修改头像</a>
<!--             <a href="javascript://" style="background:#666" onClick="$('.tab').hide();$('#tab_3').show()">修改密码</a>-->

        <?php if($rtypeid == 2) { ?>
             <a href="javascript://" style="background:#bc2933" onClick="$('.tab').hide();$('#tab_4').show();">充值记录</a>
             <a href="javascript://" style="background:#666" onClick="$('.tab').hide();$('#tab_5').show();">消费记录</a>
        <?php } ?>
        <?php }?>

    </div>
    <div class="cl"></div>
  </div>
  <div id="tab">
    <div id="tab_1" style="margin:10px;" class="ttff tab">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="th">用户性别：</td>
          <td><?php $sex=array("女","男","保密");echo  $sex[$userinfo['sex']];?>
            &nbsp;</td>
        </tr>
        <tr>
          <td  class="th">在线时长：</td>
          <td><?php echo round($userinfo['onlinetime'] /60/60, 2).'小时';?>&nbsp; 登录
            <?=$userinfo['logins']?>
            次</td>
        </tr>
        <tr>
          <td class="th">注册时间：</td>
          <td><?php echo date('Y-m-d H:i:s',$userinfo['regdate']);?>&nbsp;</td>
        </tr>
        <tr>
          <td  class="th">用户组：</td>
          <td><?php $arr=group_info($userinfo['gid']); echo $arr['title']."-".$arr['sn'];?>
            &nbsp;</td>
        </tr>
<?php
if($userinfo['gid']=='3'){


?>
        <tr>
          <td class="th">客服手机：</td>
          <td><?=$userinfo['phone']?>
            &nbsp;</td>
        </tr>
        <tr>
          <td class="th">客服QQ：</td>
          <td><a href="http://wpa.qq.com/msgrd?v=3&uin=<?=$userinfo['realname']?>&site=qq&menu=yes">
    <?=$userinfo['realname']?></a>
            &nbsp;</td>
        </tr>
<?php
}
//后台管理资料
if(check_auth('user_info_gl')){

?>
        <tr>
          <td class="th">登录IP：</td>
          <td><?=$userinfo['regip']?>
            &nbsp;</td>
        </tr>
<!--        <tr>-->
<!--          <td class="th">邮箱：</td>-->
<!--          <td>--><?//=$userinfo['email']?>
<!--            &nbsp;</td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td class="th">手机：</td>-->
<!--          <td>--><?//=$userinfo['phone']?>
<!--            &nbsp;</td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td class="th">QQ：</td>-->
<!--          <td><a href="http://wpa.qq.com/msgrd?v=3&uin=--><?//=$userinfo['realname']?><!--&site=qq&menu=yes">-->
<!--    --><?//=$userinfo['realname']?><!--</a>-->
<!--            &nbsp;</td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td class="th">用户关联：</td>-->
<!--          <td>用户客服：-->
<!--            --><?//=$userinfo['fuser']?>
<!--            &nbsp; 推广人：-->
<!--            --><?//=$userinfo['tuser']?><!--</td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td class="th">备注：</td>-->
<!--          <td>--><?//=$userinfo['sn']?>
<!--            &nbsp;</td>-->
<!--        </tr>-->
        <?php }
//end后台管理资料
?>
      </table>
<!--      <div class="user_pic"><img src="../face/img.php?t=p2&u=--><?//=$userinfo['uid']?><!--"></div>-->
    </div>
    
    <div id="tab_2" style="margin:10px;" class="ttff tab hide ">
    <form action="" method="post" enctype="application/x-www-form-urlencoded">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
              
<!--        <tr>-->
<!--          <td class="th">用户昵称：</td>-->
<!--          <td><input name="nickname" type="text" id="nickname" value="--><?//=$userinfo['nickname']?><!--"><input type="hidden" name="uid" value="--><?//=$userinfo['uid']?><!--"><input type="hidden" name="act" value="edit"></td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td  class="th">用户签名：</td>-->
<!--          <td><input name="mood" type="text" id="mood" value="--><?//=$userinfo['mood']?><!--">  </td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td class="th">联系邮箱：</td>-->
<!--          <td><input name="email" type="text" id="email" value="--><?//=$userinfo['email']?><!--"></td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td  class="th">联系QQ：</td>-->
<!--          <td><input name="realname" type="text" id="realname" value="--><?//=$userinfo['realname']?><!--"> -->
<!--            </td>-->
<!--        </tr>-->
<!--                <tr>-->
<!--          <td  class="th">联系手机：</td>-->
<!--          <td><input name="phone" type="text" id="phone" value="--><?//=$userinfo['phone']?><!--"> -->
<!--            </td>-->
<!--        </tr>-->
                        <tr>
<!--          <td  class="th">联系性别：</td>-->
<!--          <td><select name="sex" id="sex">-->
<!--            <option value="--><?//=$userinfo['sex']?><!--">--><?php //$sex=array("女","男","保密");echo  $sex[$userinfo['sex']];?><!--</option>-->
<!--            <option value="1">男</option>-->
<!--            <option value="0">女</option>-->
<!--            <option value="2">保密</option>-->
<!--          </select>-->
<!--            </td>-->
        </tr>
                        <tr>
          <td  class="th">用户头像：</td>
          <td> <span id="ep1"></span> <span id="ep2"></span></td>
        </tr>
                                <tr>
          <td  class="th">&nbsp;</td>
          <td> <input type="submit" value="保存" class="bc" style="width:40px; border:0px;"></td>
        </tr>
      </table>
      </form>
<!--      <div class="user_pic"><img src="../face/img.php?t=p2&u=--><?//=$userinfo['uid']?><!--"></div>-->
      <div class="user_edit_pic"><div id="epf"></div>
      <input type="button" onClick="saveToServer();" class="bc"  value="确定"  style="width:40px; border:0px;"> 
      <input type="button" onClick="$('.user_edit_pic').hide()" class="bc"  value="取消" style="width:40px; border:0px; background:#666"></div>
    </div>

      <div id="tab_3" style="margin:10px;" class="ttff tab hide">
          <form action="" method="post" enctype="application/x-www-form-urlencoded">
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                      <td class="th">旧密码：</td>
                      <td><input name="oldpwd" type="password" id="oldpwd" ><input type="hidden" name="uid" value="<?=$userinfo['uid']?>"><input type="hidden" name="act" value="editpwd"></td>
                  </tr>
                  <tr>
                      <td  class="th">新密码：</td>
                      <td><input name="pwd1" type="password" id="pwd1">  </td>
                  </tr>
                  <tr>
                      <td class="th">确认密码：</td>
                      <td><input name="pwd2" type="password" id="pwd2"></td>
                  </tr>
                  <tr>
                      <td  class="th">&nbsp;</td>
                      <td> <input type="submit" value="保存" class="bc" style="width:40px; border:0px;"></td>
                  </tr>
              </table>
          </form>
      </div>


      <style>
          .account-balance p{
              font-size: 24px;
              text-align: center;
          }
          .account-balance p em{
              font-size: 55px;
              color: #be2632;
          }
          .account-balance p a{
              display: inline-block;
              font-size: 12px;
              color: #fff;
              line-height: 22px;
              padding: 0 10px;
              border-radius: 5px;
              background: #be2632;
              margin-left: 20px;
          }
          .balance-czjl{
              padding:20px 0 10px 20px;
              border-bottom: solid 1px #121212;
          }
          .search-mod_order-search-button, .search-mod_order-search-input {
              box-sizing: border-box;
              display: inline-block;
              height: 22px;
              vertical-align: middle;
              border: solid 1px #c9c9c9;
          }
          .search-mod_order-search-input {
              width: 96px;
              padding: 0 8px;
          }
          .search-mod_order-search-button{
              background: #7a7a7a;
              padding: 0 15px;
              color: #fff;
              border: none;
              margin-left: 20px;
              cursor:pointer;
          }
          .balance-jyjl{
              margin-left: 100px;
          }
          .balance-price{
              margin-left: 40px;
          }
          .list_box{
              color: #333;
          }
          .balance-czjl{
              padding:20px 0 10px 20px;
              border-bottom: solid 1px #121212;
          }
          .search-mod_order-search-button, .search-mod_order-search-input {
              box-sizing: border-box;
              display: inline-block;
              height: 22px;
              vertical-align: middle;
              border: solid 1px #c9c9c9;
          }
          .search-mod_order-search-input {
              width: 96px;
              padding: 0 8px;
          }
          .search-mod_order-search-button{
              background: #7a7a7a;
              padding: 0 15px;
              color: #fff;
              border: none;
              margin-left: 20px;
              cursor:pointer;
          }
          .balance-jyjl{
              margin-left: 100px;
          }
          .balance-price{
              margin-left: 40px;
          }
          .abtit{
              font-size: 18px;
          }
          .order-table{
              width: 100%;
          }
          .order-table th,.order-table td{
              text-align: center;
              height: 40px;
              border-bottom: solid 1px #cbcbcb;
          }
          .order-table th{
              font-weight: normal;
          }
          .order-table tr.grb{
              background: #f5f5f5;
          }
          .m-pagging{
              text-align: center;
              padding-top: 10px;
          }
          .m-pagging a{
              display:inline-block;
              height:25px;
              line-height:25px;
              padding:0 10px;
              margin:0 2px;
          }
          .m-pagging .ajaxify:hover {
              display:inline-block;
              height:25px;
              line-height:25px;
              padding:0 10px;
          // margin:0 2px;
              border-radius:4px;
              text-decoration:none;
              background-color:#BC2933;
              color:#fff;
          }
          .m-pagging .current {
              display:inline-block;
              height:25px;
              line-height:25px;
              padding:0 10px;
              margin:0 2px;
              color:#fff;
              background-color:#BC2933;
              border-radius:4px;
              vertical-align:middle
          }
          .m-pagging a.z-current{
              color: #333;
          }

      </style>

      <div id="tab_4" style="margin:10px;" class="ttff tab hide">
          <div class="main">
              <div class="main-left width-100" style="margin-top:0px">
                  <table class="table table-hover" border="0" cellspacing="0" cellpadding="0">
                      <thead>
                      <tr>
                          <th>充值时间</th>
                          <th>充值数额</th>
                      </tr>
                      </thead>

                      <tbody id="tbinfo1">
                      </tbody>

                      <tfoot>
                      <tr>
                          <td colspan="5" id="Page1">

                          </td>
                      </tr>
                      </tfoot>
                  </table>
              </div>
          </div>
      </div>

      <div id="tab_5" style="margin:10px;" class="ttff tab hide">
          <div class="main">
              <div class="main-left width-100" style="margin-top:0px">
                  <table class="table table-hover" border="0" cellspacing="0" cellpadding="0">
                      <thead>
                      <tr>
                          <th>消费时间</th>
                          <th>消费物品</th>
                          <th>消费数量</th>
                          <th>消费总数</th>
                      </tr>
                      </thead>

                      <tbody id="tbinfo">
                      </tbody>

                      <tfoot>
                      <tr>
                          <td colspan="5" id="Page">

                          </td>
                      </tr>
                      </tfoot>
                  </table>
              </div>
          </div>

      </div>
  </div>
</div>
<?=$msg?>
<script type="text/javascript" src="../upload/swfupload/swfupload.js"></script>
<script>
    
    
        var config = ({
            Mode    : 2,                                        //分页模式 1:普通分页
            PageBer : 5,                                       //每页显示条数
            PageMax : 6,                                       //每页最多显示多少个页码
            PageUrl : './api/gifCostList.php?page=[#]&uid=<?php echo $uid;?>',  //分页链接,并带上分页符
            PageId  : 'Page',                                   //分页Page实体插入的HTML ID
            PageCid : 'tbinfo',                                 //分页内容插入的HTML ID
            PageHtml: '<tr><td>[8]</td><td><a>[2]</a></td><td>[9]</td><td>-[10] 钻</td></tr>',//分页实体,带占位符0-N键位 指定字段
            PageArray: '',                                      //JSON化之后的分页内容
            Page    : 1,                                        //当前分页数
            PageNum : 2,                                       //分页总记录数
            /*Ajax模式下的分页参数*/
            Ajax    : 'get',                                    //ajax模式
            AjaxNo  :   null,                              //分页里需要替换的文件名   不需要替换设置为null
            AjaxYes : 'ajax_3.php'                             //分页替换的文件名
        });
        JunPage(config);
        //调用分页


</script>

<script>

        var config = ({
            Mode: 2,                                        //分页模式 1:普通分页
            PageBer: 5,                                       //每页显示条数
            PageMax: 6,                                       //每页最多显示多少个页码
            PageUrl: './api/gifRechargeList.php?page=[#]&uid=<?php echo $uid;?>',  //分页链接,并带上分页符
            PageId: 'Page1',                                   //分页Page实体插入的HTML ID
            PageCid: 'tbinfo1',                                 //分页内容插入的HTML ID
            PageHtml: '<tr><td>[8]</td><td><a>+ [10] 钻</a></td></tr>',//分页实体,带占位符0-N键位 指定字段
            PageArray: '',                                      //JSON化之后的分页内容
            Page: 1,                                        //当前分页数
            PageNum: 2,                                       //分页总记录数
            /*Ajax模式下的分页参数*/
            Ajax: 'get',                                    //ajax模式
            AjaxNo: null,                              //分页里需要替换的文件名   不需要替换设置为null
            AjaxYes: 'ajax_3.php',                             //分页替换的文件名
        });
        JunPage(config);
        //调用分页
</script>

<script>
function thisMovie(movieName)
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		return window[movieName];
	}
	else
	{
		return document[movieName];
	}
}
function loadImage()
{
	thisMovie("PhotoEditor").loadImage(img);
}
function flashInit(arg)
{
	setTimeout('loadImage()', 1000);
}
function init()
{
}
function flashError(event)
{
	//alert(event.code);
	switch(event.code)
	{
		case 0:
		if (event.msg == "图片加载成功！")
		{
			return;
		}
		if (1)
		{
			location.reload();
		}
		break;
		case "#1057":
		//Fid('errDiv').innerHTML = '选择的照片太小，请';
		break;
	}
}
function saveToServer()
{
	var b=thisMovie('PhotoEditor').saveToServer('profiles.php?editface='+ept+'&w');
}
  function swfupload_ok(fileObj,server_data){
	  $('.user_edit_pic').show();
	  var data=eval("("+server_data+")") ;
	  img=data.msg.url;
	  var wh;
	  if(data.msg.info=="ep1"){wh="slice_width=100&slice_height=100"; ept='p1'}
	  else {wh="slice_width=110&slice_height=150"; ept='p2'}
	  
	  var so = new SWFObject("../images/PhotoEditor.swf?imageEncoder=jpg&jpgQuality=97&"+wh, 'PhotoEditor', "325", "312", "9", "#FFF");	
		  so.write("epf");
	 
	 //alert(server_data);
	 //var data=eval("("+server_data+")") ;
	 //$("#"+data.msg.info).val(data.msg.url);
  }
  $(function(){


  var swfdef={
	  // 按钮设置
	    file_post_name:"filedata",
		button_width: 60,
		button_height: 28,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		button_text: '修改头像',
		button_text_style: ".upbnt{}",
		button_text_left_padding: 0,
		button_text_top_padding: 10,
		upload_success_handler : swfupload_ok,
		file_dialog_complete_handler:function(){this.startUpload();},
		file_queue_error_handler:function(){alert("选择文件错误");}
		}
  swfdef.flash_url="../upload/swfupload/swfupload.swf";
  swfdef.button_placeholder_id="ep1";
  swfdef.file_types="*.png;*.jpg;*.gif";
  swfdef.upload_url="../upload/upload.php";
  swfdef.post_params={"info":"ep1"}
  
  swfu = new SWFUpload(swfdef);
  
  var swfico=swfdef;
  swfico.button_text='修改照片';
  swfico.button_placeholder_id="ep2";
  swfico.post_params={"info":"ep2"}
  swfuico = new SWFUpload(swfico);
	  
});

//时间戳转换日期
function UnixToDate(unixTime, isFull, timeZone) {
    //0-9添加0
    function add_zero(num){
        if( 0 <= Number(num) && Number(num) <= 9  ){
            num = '0'+num;
        }
        return num;
    }

    if (typeof (timeZone) == 'number')
    {
        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
    }
    var time = new Date(unixTime * 1000);
    var ymdhis='';

    ymdhis += add_zero(time.getUTCFullYear()) + "-";
    ymdhis += add_zero((time.getUTCMonth()+1)) + "-";
    ymdhis += add_zero(time.getUTCDate());

    if (isFull === true)
    {
        ymdhis += " " + add_zero(time.getUTCHours()) + ":";
        ymdhis += add_zero(time.getUTCMinutes()) + ":";
        ymdhis += add_zero(time.getUTCSeconds());
    }
    return ymdhis;
}
</script>
</body>
</html>
